package cn.stylefeng.guns.modular.agv.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.agv.entity.AgvStoragePosition;
import cn.stylefeng.guns.modular.agv.mapper.AgvStoragePositionMapper;
import cn.stylefeng.guns.modular.agv.model.params.AgvStoragePositionParam;
import cn.stylefeng.guns.modular.agv.model.result.AgvStoragePositionResult;
import  cn.stylefeng.guns.modular.agv.service.AgvStoragePositionService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * AGV拣选库位表 服务实现类
 * </p>
 *
 * @author zhangzh
 * @since 2024-08-09
 */
@Service
public class AgvStoragePositionServiceImpl extends ServiceImpl<AgvStoragePositionMapper, AgvStoragePosition> implements AgvStoragePositionService {

    @Override
    public void add(AgvStoragePositionParam param){
        AgvStoragePosition entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(AgvStoragePositionParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(AgvStoragePositionParam param){
        AgvStoragePosition oldEntity = getOldEntity(param);
        AgvStoragePosition newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public AgvStoragePositionResult findBySpec(AgvStoragePositionParam param){
        return null;
    }

    @Override
    public List<AgvStoragePositionResult> findListBySpec(AgvStoragePositionParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(AgvStoragePositionParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(AgvStoragePositionParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private AgvStoragePosition getOldEntity(AgvStoragePositionParam param) {
        return this.getById(getKey(param));
    }

    private AgvStoragePosition getEntity(AgvStoragePositionParam param) {
        AgvStoragePosition entity = new AgvStoragePosition();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
